<template>
  <CommonCard title="累计用户数" :value="numberFormat(useReport.reportInfo.usersTotal)">
    <template #default>
      <div ref="barRef" style="width:100%;height:100%"></div>
    </template>
    <template #footer>
      <div class="footer">
        <span>日同比</span>
        <span class="emphasis">{{useReport.reportInfo.userGrowthLastDay}}%</span>
        <span class="increment"></span>
        <span style="margin-left:10px">月同比</span>
        <span class="emphasis">{{useReport.reportInfo.userGrowthLastMonth}}%</span>
        <span class="decrement"></span>
      </div>
    </template>
  </CommonCard>
</template>

<script lang="ts">
export default {
  name: 'TotalUsers'
}
</script>
<script lang="ts" setup>
import CommonCard from './commonCard.vue'
import { ref, onMounted ,watch} from 'vue'
import * as echarts from 'echarts'
import type { EChartsType } from 'echarts'
import { useReportDataStore } from "@/stores/reportData"
import useFormat from "@/hooks/useFrmat"
const { numberFormat, moneyFormat } = useFormat()
const useReport = useReportDataStore()
const barRef = ref()
let mChart: EChartsType;

const getOption = () => {
  return {
    xAxis: {
      show: false,
      min: 0,
      max: 100
    },
    yAxis: {
      show: false,
      // 将X轴的数据项给到Y轴，从而让柱条以水平方向和呈现
      data: [useReport.reportInfo.usersLastMonth]
    },
    series: {
      type: 'bar',
      data: [78],
      barWidth: 10,
      showBackground: true,
      itemStyle: {
        color: 'orangered'
      }
    },
    grid: {
      left: 0,
      right: 0
    },
    // 设置刻度样式
    label: {
      show: true,
      // 把文字改成竖线
      formatter: '|',
      color: 'orangered',
      position: 'right'
    }
  }
}
onMounted(() => {
  mChart = echarts.init(barRef.value)
  
})
watch(()=>{
  return useReport.reportInfo.usersTotal
}, () => {
  mChart.setOption(getOption())
})
</script>

<style lang="scss" scoped>
.footer {
  display: flex;
  align-items: center;
}
</style>